<?php
require_once("database.php");
class xl_lien_he extends database
{
	function danh_sach($vi_tri, $so_luong)
	{
		$vi_tri = intval($vi_tri);
		$so_luong = intval($so_luong);
		$sql = "select * from lien_he ORDER BY trang_thai ASC limit $vi_tri, $so_luong";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	function so_luong()
	{
		$sql = "select count(*) from lien_he";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function xem($ma)
	{
		$ma = intval($ma);

		$sql = "select * from lien_he where ma = '$ma'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	function xoa($ma)
	{
		$ma = intval($ma);

		$sql = "delete from lien_he where ma = '$ma'";
		$this->setQuery($sql);
		$this->query();
	}
	function them($ho_ten, $email, $tieu_de, $noi_dung, $ngay_tao, $trang_thai)
	{
		$ho_ten = addslashes($ho_ten);
		$email = addslashes($email);
		$tieu_de = addslashes($tieu_de);
		$noi_dung = addslashes($noi_dung);

		$sql = "INSERT INTO lien_he(ho_ten,email,tieu_de,noi_dung,ngay_tao,trang_thai) VALUES ('$ho_ten','$email','$tieu_de','$noi_dung','$ngay_tao','$trang_thai')";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat($ma, $ho_ten, $email, $tieu_de, $noi_dung, $ngay_tao, $trang_thai)
	{
		$ma = intval($ma);
		$ho_ten = addslashes($ho_ten);
		$email = addslashes($email);
		$tieu_de = addslashes($tieu_de);
		$noi_dung = addslashes($noi_dung);

		$sql ="UPDATE lien_he SET ho_ten= '$ho_ten', email= '$email', tieu_de= '$tieu_de', noi_dung= '$noi_dung', ngay_tao= '$ngay_tao', trang_thai= '$trang_thai' WHERE ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat_tt($ma)
	{
		$ma = intval($ma);
		$sql ="UPDATE lien_he SET trang_thai= 1-trang_thai WHERE ma = '$ma'";
		$this->setQuery($sql);
		return $this->query();
	}
	function tim_kiem ($tu_khoa)
	{
		$sql = "select * from lien_he where	$ho_ten like %tu_khoa% or 	$email like %tu_khoa% or 	$tieu_de like %tu_khoa% or  	$noi_dung like %tu_khoa%"; 
		$this->setQuery($sql);
		return $this->loadAllRow();	
	}
 }
?>